#!/usr/bin/env python3
"""
调试配置文件实际使用的配置
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

import configparser
from mysql_storage import MySQLStorage

def debug_config():
    """调试实际使用的配置"""
    print("=== 配置文件调试信息 ===")
    
    # 1. 检查当前目录的config.ini
    config_path = os.path.join(os.getcwd(), 'config.ini')
    print(f"1. 配置文件路径: {config_path}")
    print(f"   文件存在: {os.path.exists(config_path)}")
    
    if os.path.exists(config_path):
        config = configparser.ConfigParser()
        config.read(config_path, encoding='utf-8')
        if 'database' in config:
            print("   [database]配置:")
            for key, value in config['database'].items():
                print(f"     {key} = {value}")
    
    # 2. 检查MySQLStorage实际使用的配置
    print("\n2. MySQLStorage默认配置:")
    print("   代码中默认配置:")
    default_config = {
        "host": "3.76.79.249",
        "port": "3306",
        "user": "getbyemsData",
        "password": "getbyemsData",
        "db": "getbyemsData",
    }
    for key, value in default_config.items():
        print(f"     {key} = {value}")
    
    # 3. 创建测试实例（不实际连接）
    print("\n3. 创建MySQLStorage实例测试...")
    try:
        # 创建一个不连接的实例来查看配置
        storage = MySQLStorage.__new__(MySQLStorage)
        storage.config_file = "config.ini"
        storage._is_init = False
        
        # 手动加载配置
        config = configparser.ConfigParser()
        config_path = os.path.join(os.path.dirname(__file__), "config.ini")
        
        if os.path.exists(config_path):
            config.read(config_path, encoding='utf-8')
            if 'database' in config:
                actual_config = dict(config['database'])
                print("   实际从配置文件读取:")
                for key, value in actual_config.items():
                    print(f"     {key} = {value}")
            else:
                print("   使用默认配置（未找到[database]）")
        else:
            print("   使用默认配置（配置文件不存在）")
            
    except Exception as e:
        print(f"   错误: {e}")

if __name__ == "__main__":
    debug_config()